/** 
 *  @file       lcd_display.h
 *  @brief      项目程序头文件
 *  @author     Z B T   
 *  @version    
 *  @date       2016-01-18
 */
 
 /* Includes ------------------------------------------------------------------*/
#include "lcd_display.h"
#include "lcd1602.h"
//#include "ds18b20.h"
#include "at24c02.h"
#include "key.h"
#include "delay.h"

sbit key_1 = P1^0;
/* Private variables ---------------------------------------------------------*/
unsigned char array_write[] = "Write:";
unsigned char array_read[]  = "Read: ";
unsigned char psw0[6] = {1, 0, 0, 6, 2, 4};
unsigned char psw1[6];

/* Private function prototypes ------------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/* Public functions ---------------------------------------------------------*/
/**
 *  @brief  lcd1602显示ds18b20的温度值
 *  @param  None
 *  @return None
 */
//void lcd_display_temperature()
//{
//    signed int value;
//    unsigned int temperature_value[3];
//    
//    value = DS18B20_get_temperature();
//    temperature_value[0] = value / 100;
//    temperature_value[1] = value / 10 % 10;
//    temperature_value[2] = value % 10;
//    
//    LCD1602_write_cmd(0x80);
//    if (value > 0)
//    {
//        LCD1602_write_data('+');        /**< 温度值大于0 */
//    }
//    else
//    {
//        LCD1602_write_data('-');        /**< 温度值小于0 */
//    }
//    LCD1602_write_data('0' + temperature_value[0]);
//    LCD1602_write_data('0' + temperature_value[1]);
//    LCD1602_write_data('0' + temperature_value[2]);
//    LCD1602_write_data('C');  
//}

/**
 *  @brief  lcd1602显示AT24C02的值初始化界面显示
 *  @param  None
 *  @return None
 */
 void lcd_display_eeprom_init(void)
 {
     unsigned char i;
     
     LCD1602_write_cmd(0x80);
     for (i = 0; i < 6; i++)
     {
         LCD1602_write_data(array_write[i]);
     }
     LCD1602_write_cmd(0x80 + 0x40);
     for (i = 0; i < 6; i++)
     {
         LCD1602_write_data(array_read[i]);
     }
     
     for (i = 0; i < 6; i++)
     {
         AT24C02_write(i, psw0[i]);
         delay_ms(10);
     }
     for (i = 0; i < 6; i++)
     {
         psw1[i] = AT24C02_read(i);
         delay_ms(10);
     }
 }
 
/**
 *  @brief  lcd1602根据按键选择显示\读取AT24C02的值初始化界面显示
 *  @param  None
 *  @return None
 */
 void lcd_display_eeprom(void)
 {
     unsigned char i;
     
     switch (key_scan())
     {
     case KEY_3:
         for (i = 0; i < 6; i++)
         {
             AT24C02_write(i, psw0[i]);
             delay_ms(10);
         }
         delay_ms(2000);
         for (i = 0; i < 6; i++)
         {
             psw1[i] = AT24C02_read(i);
             delay_ms(10);
         }
         break;
     case KEY_2:
         for (i = 0; i < 6; i++)
         {
             psw1[i] = AT24C02_read(i);
             delay_ms(10);
         }
         break;
     case KEY_1:
         for (i = 0; i < 6; i++)
         {
             psw0[i] += i;
         }
         break;
     default:
         break;
     }
}
